﻿var Utils = {};

Utils.getTime = function() {
    var d = new Date();
    d.setDate(new Date().getDate());
    return d.toTimeString().substr(0, d.toTimeString().lastIndexOf(":"));
    //var time = d.toTimeString().substr(0, d.toTimeString().lastIndexOf(" "));
    //return (time + d.toLocaleTimeString().substr(d.toLocaleTimeString().lastIndexOf(" ")));
}

Utils.getTimeWithSeconds = function() {
    var d = new Date();
    d.setDate(new Date().getDate());
    return d.toTimeString().substr(0, d.toTimeString().lastIndexOf(" "));
}

Utils.formatMessage = function(_sMessage) {
    var retStr = _sMessage;
    retStr = Utils.sanitizeMsg(retStr);
    //retStr += "<br />";

    return retStr;
}

Utils.sanitizeMsg = function(sMsg) {
    var trimChars = ["<", ">", "\n"];
    var safeChars = ["&lt;", "&gt;", "<br />"];
    var retString = sMsg;

    for (var i = 0; i < trimChars.length; i++) {
        while (retString.indexOf(trimChars[i]) != -1) {
            retString = retString.replace(trimChars[i], safeChars[i]);
        }
    }

    return retString;
}

Utils.pxToInt = function(sPixels) {
    return parseInt(sPixels.replace('px', ''));
}

Utils.isValidEmail = function(strEmail) {
    var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    return strEmail.match(emailRegEx);
}